"""
使用生成器的方式实现sse
基于flask框架
<没有卵用>
"""
import time
from flask import Flask, Response

app = Flask(__name__)


def generate_events():
    while True:
        yield f'data: {time.ctime()}\n\n'
        time.sleep(1)


@app.route("/events")
async def sse_endpoint():
    return Response(generate_events(), mimetype="text/event-stream")


if __name__ == '__main__':
    app.run()
